﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Accounting.Web.Models;

namespace Accounting.Views
{
    public partial class Accounting : Page
    {
        public Accounting()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void goodDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void btnNewRecord_Click(object sender, RoutedEventArgs e)
        {
            Good good = new Good();
            if (warehouseDomainDataSource.DataView.Count > 0)
                good.Warehouse_Id = ((Warehouse)warehouseDomainDataSource.DataView[0]).Id;
            good.Synced = false;
            goodDomainDataSource.DataView.Add(good);
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            goodDomainDataSource.SubmittedChanges += new EventHandler<SubmittedChangesEventArgs>(goodDomainDataSource_SubmittedChanges);
            goodDomainDataSource.SubmitChanges();
        }

        void goodDomainDataSource_SubmittedChanges(object sender, SubmittedChangesEventArgs e)
        {
            
        }

        private void btnDiscard_Click(object sender, RoutedEventArgs e)
        {
            goodDomainDataSource.RejectChanges();
        }

        private void warehouseDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
        }

        private void btnWarehouses_Click(object sender, RoutedEventArgs e)
        {
            Warehouses warehouses = new Warehouses();
            warehouses.Show();
        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Record will be deleted. Are you sure?", "Confirmation", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                goodDomainDataSource.DataView.Remove(goodDomainDataSource.DataView.CurrentItem);
            }

        }

    }
}
